﻿using System.Text.Json.Serialization;

namespace KinonekoSoftware.Studio.Models
{
    public class VersionInformation
    {
        public static uint GetVersion(int major, int minor, int buildNumber, int revision)
        {
            return (uint)((major       & 0x3f)  << 26 |
                          (minor       & 0x7f)  << 19 |
                          (buildNumber & 0x1ff) << 10 |
                          (revision & 0x3ff));
        }


        /// <summary>
        /// 主版本号
        /// </summary>
        [JsonIgnore]
        public int MajorVersion => (int)((Version & 0xfc000000) >> 26);

        /// <summary>
        /// 次版本号
        /// </summary>
        [JsonIgnore]
        public int MinorVersion => (int)((Version & 0x3F80000) >> 19);

        /// <summary>
        /// 内部版本号
        /// </summary>
        [JsonIgnore]
        public int BuildNumber => (int)((Version & 0x7fc00) >> 10);

        /// <summary>
        /// 修订号
        /// </summary>
        [JsonIgnore]
        public int Revision => (int)(Version & 0x3ff);
        
        /// <summary>
        /// 这是真实的版本号，应该以 1.0.0 + 51247 来代替
        /// </summary>
        /// <remarks>
        /// <para>前6位是Major Version，也就是主版本号，最多63</para>
        /// <para>前7位是Minor Version，也就是次版本号，最多127</para>
        /// <para>前9位是Build Number，也就是内部版本号，最多511</para>
        /// <para>前10位是Revision，也就是修订号，最多1023</para>
        /// </remarks>
        public uint Version { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        public List<string> UpgradeUrls { get; init; }
    }
}